package test2;

import java.util.ArrayList;
import java.util.List;

public class Document {
    private static final List<String> paragraphs = new ArrayList<>();

    public static void readDocument(String text) {
        int start = 0;
        int end = 20;

        while (end <= text.length()) {
            String paragraph = text.substring(start, end);
            paragraphs.add(paragraph);

            start = end;
            end += 20;
        }

        if (start < text.length()) {
            String lastParagraph = text.substring(start);
            paragraphs.add(lastParagraph);
        }
    }

    public static void searchParagraphs(String keyword) {
        for (String paragraph : paragraphs) {
            if (paragraph.contains(keyword)) {
                System.out.println(paragraph);
            }
        }
    }

    public static void main(String[] args) {
        // 调用readDocument方法读取文本并存储到静态变量
        readDocument("这是一个示例文档，用于测试读取和搜索功能。文档包含多个段落，每个段落长度限制为20个字符。");

        // 调用searchParagraphs方法根据关键字搜索并打印符合条件的段落
        searchParagraphs("示例");
    }
}